package com.atguigu.gmall.web.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.feign.item.SkuDetailsFeignClient;
import com.atguigu.gmall.product.vo.SkuDetailVo;
import com.atguigu.gmall.feign.product.ProductSkuDetailsFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

/**
 * @author tangsy
 * @Description TODO
 * @date 2022/12/3 16:08
 * @Version 1.0
 */
@Controller
public class ItemController {

    @Autowired
    SkuDetailsFeignClient SkuDetailsFeignClient;

    @GetMapping("/{skuId}.html")
    public String itemPage(@PathVariable("skuId")Long skuId, Model model){

        Result<SkuDetailVo> skuDetails = SkuDetailsFeignClient.getSkuDetails(skuId);
        SkuDetailVo detailVo = skuDetails.getData();

        //1 分类视图
        model.addAttribute("categoryView",detailVo.getCategoryView());

        //2 sku信息
        model.addAttribute("skuInfo",detailVo.getSkuInfo());

        //3 实时价格
        model.addAttribute("price",detailVo.getPrice());

        //4 所有销售属性集合
        model.addAttribute("spuSaleAttrList",detailVo.getSpuSaleAttrList());

        //5 valueSkuJson
        model.addAttribute("valuesSkuJson",detailVo.getValuesSkuJson());


        return "item/index";
    }

}
